#include "stu.h"
Visitor *p;//申请堆内存，存放登录信息
Visitor *v;//活跃指针
int exit_flag;//系统即将退出的标志
bool quit_flag;
float Getmax(const int cmd)
{
	int max=0;
	Visitor *dest=&p[0];
	if(cmd!=0&&cmd!=1&&cmd!=2)
	{
		printf("命令错误!");
		return 0;
	}
	while(Translate(dest->level)!=NULL)
	{
		if(max<dest->grade[cmd])
		max=dest->grade[cmd];
		dest++;
	}
	return max;
}
float Getmin(const int cmd)
{
	int min=0;
	Visitor *dest=&p[0];
	if(cmd!=0&&cmd!=1&&cmd!=2)
	{
		printf("命令错误!");
		return 0;
	}
	while(Translate(dest->level)!=NULL)
	{
		if(min>dest->grade[cmd])
		min=dest->grade[cmd];
		dest++;
	}
	return min;
}
float Getaverage(const int cmd,const int id)
{
	int sum=0;
	Visitor *dest=&p[0];
	if(cmd!=0&&cmd!=1&&cmd!=2&&cmd!=3)
	{
		printf("命令错误!");
		return 0;
	}
	if(cmd!=3){
		while(Translate(dest->level)!=NULL)
		{
			sum+=dest->grade[cmd];
			dest++;
		}
		return sum/Getgroupnumber('s');
	}
	else
	{
		dest=Findmember(id);
		float avg=(dest->grade[0]+dest->grade[1]+dest->grade[2])/3;
		return avg;
	}
}
int Getrank(const int id)
{
	Visitor *dest = Findmember(id);
	dest = &p[0];
	int rank=1;
	while(Translate(dest->level)!=NULL)
	{
		if(Getaverage(3,v->id)<Getaverage(3,dest->id))
		{
				rank++;
		}
		dest++;
	}
	return rank;
}
void Displaygrade(const int id,const char level)
{
	if(!Findid(id))
	{
		printf("此%s不存在!\n",Translate(Lowerlevel(level)));
		Anykey();
		return;
	}
	Visitor *dest=Findmember(id);
	if(!Levelcmp(level,dest->level))
	{
		printf("此学工号对应的身份是%s,您无权对其进行操作!\n",Translate(dest->level));
		Anykey();
		return;
	}
	printf("语文:%.1f\n数学:%.1f\n英语:%.1f\n语文平均分:%.1f\n数学平均分:%.1f\n英语平均分:%.1f\n排名:%d\n",dest->grade[0],dest->grade[1],dest->grade[2],Getaverage(0,dest->id),Getaverage(1,dest->id),Getaverage(2,dest->id),Getrank(id));
	Anykey();
		return;
}
